/*

Racial prejudice, education, and views of climate change (Forthcoming at Social Science Quarterly)
Authors: Salil D. Benegal and Mirya R. Holman, 5/26/2021

All commands/functions pertain to the original files from ANES "anes_timeseries_2016_Stata13.dta" and "anes_timeseries_2012.dta".

This file uses a cleaned and combined 2012/2016 ANES dataset for our ANES analysis. */

clear
set more off

///set scheme plottig
/// set scheme burd
set scheme lean2
/// set scheme cblind
/// set scheme economist
/// set scheme mrc
/// set scheme plotplain
/// set scheme modern
graph set window fontface "Times New Roman"

cd "C:\Users\HolmanMirya\Dropbox (MH)\Benegal_Holman_Beatty\racial_resentment_edu\data"
use "ANES_combined.dta"


label variable educxrr "Education * Racial Resentment" 
label variable income1 "Income" 
label variable educlevel "Education" 
label variable Democrat "Democrat" 
label variable Republican "Republican" 
label variable Liberal "Liberal" 
label variable Conservative "Conservative" 
label variable male "Male" 
label variable age "Age" 
label variable Liberal "Liberal" 
label variable white2 "White" 


egen mean_resent = mean(resentment), by(educlevel)
label variable mean_resent "Resentment by education level"

************************

// Results for Table 1, part A

eststo clear 

eststo m2: logit gwhappening resentment educlevel educxrr Democrat Republican Liberal Conservative male age income1 if white==1, cluster(survey)
eststo m1: logit gwhappening resentment educlevel Democrat Republican Liberal Conservative male age income1 if white==1, cluster(survey)
eststo m4: logit humanactivity resentment educlevel educxrr Democrat Republican Liberal Conservative male age income1 if white==1, cluster(survey)
eststo m3: logit humanactivity resentment educlevel Democrat Republican Liberal Conservative male age income1 if white==1, cluster(survey)


# delimit ;
esttab using Table1_ANESresults2.rtf, nogap se b b(%9.4f) starlevels(* .10 ** .05 *** .01) r2(%9.3f) 
	title("Belief global warming is happening / caused by humans" )
	  label nonumbers mtitles("Happening" "Happening" "Human caused" "Human caused")
	addnote("Logistic regression. Combined 2012 and 2016 data with errors clustered on survey")
	compress replace;
 #delimit cr
 

// Results for Figure 1 //

eststo clear 
	logit gwhappening c.resentment##c.educlevel Democrat Republican Liberal Conservative male age income1 if white==1
	eststo edu1: margins, at(resentment=(1(.5)5) educlevel=(1))   atmeans post 
	logit gwhappening c.resentment##c.educlevel  Democrat Republican Liberal Conservative male age income1 if white==1
	eststo edu4: margins, at(resentment=(1(.5)5) educlevel=(4))  atmeans post 

coefplot (edu1, label (High school or less)) (edu4, label (BA degree)), ///
	ytitle ("Global Warming is Happening" "Predicted values")   title("") legend (row(1) pos(6)) ///
	xtitle ("Racial Resentment") ///
	xlab(1 "Low" 3 "Medium" 5 "High", labsize(small)) ///
	ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%", labsize(small)) ///
	at recast(line) lwidth(*2) 
	graph save figure1a.gph, replace


eststo clear 
	logit humanactivity c.resentment##c.educlevel Democrat Republican Liberal Conservative male age income1 if white==1
	eststo edu1b: margins, at(resentment=(1(.5)5) educlevel=(1))   atmeans post 
	logit humanactivity c.resentment##c.educlevel  Democrat Republican Liberal Conservative male age income1 if white==1
	eststo edu4b: margins, at(resentment=(1(.5)5) educlevel=(4))  atmeans post 

coefplot (edu1b, label (High school or less)) (edu4b, label (BA degree)), ///
	ytitle ("Climate Change Primarily Caused by Humans" "Predicted values")   title("") legend (row(1) pos(6)) ///
	xtitle ("Racial Resentment") ///
	xlab(1 "Low" 3 "Medium" 5 "High", labsize(small)) ///
	ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%", labsize(small)) ///
	at recast(line) lwidth(*2)  
	graph save figure1b.gph, replace 
	
grc1leg  figure1a.gph figure1b.gph,  ycommon row(1) graphregion(margin(none)) ysize(4) 
graph save 1F_ANES.gph, replace
graph export 1F_ANES.png, replace width(1800)

	
	
***** models by partisanship **** 	

 eststo clear 
 
 
	logit humanactivity c.resentment##c.educlevel Democrat Republican Liberal Conservative male age income1 if white==1  & Democrat == 1
	eststo edu1: margins, at(resentment=(1(.5)5) educlevel=(1))   atmeans post 
	logit humanactivity c.resentment##c.educlevel  Democrat Republican Liberal Conservative male age income1 if white==1  & Democrat == 1
	eststo edu2: margins, at(resentment=(1(.5)5) educlevel=(4))  atmeans post 
 
	logit humanactivity c.resentment##c.educlevel Democrat Republican Liberal Conservative male age income1 if white==1  & Republican == 1
	eststo edu3: margins, at(resentment=(1(.5)5) educlevel=(1))   atmeans post 
	logit humanactivity c.resentment##c.educlevel  Democrat Republican Liberal Conservative male age income1 if white==1  & Republican == 1
	eststo edu4: margins, at(resentment=(1(.5)5) educlevel=(4))  atmeans post 
	
	

coefplot (edu1, label (High school or less)) (edu2, label (BA degree)), ///
	ytitle ("Climate Change Primarily Caused by Humans" "Predicted values")   title("Democrats") legend (row(1) pos(6)) ///
	xtitle ("Racial Resentment") ///
	xlab(1 "Low" 3 "Medium" 5 "High", labsize(small)) ///
	ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%", labsize(small)) ///
	at recast(line) lwidth(*2)  
	graph save human_dem.gph, replace 

	
coefplot (edu3, label (High school or less)) (edu4, label (BA degree)), ///
	ytitle ("Climate Change Primarily Caused by Humans" "Predicted values")   title("Republicans") legend (row(1) pos(6)) ///
	xtitle ("Racial Resentment") ///
	xlab(1 "Low" 3 "Medium" 5 "High", labsize(small)) ///
	ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%", labsize(small)) ///
	at recast(line) lwidth(*2) 
	graph save human_rep.gph, replace

grc1leg human_dem.gph human_rep.gph, ycommon row(1) graphregion(margin(none)) ysize(4) 
graph save 4F_ANES_PID.gph, replace
graph export 4F_ANES_PID.png, replace width(1800)



**** appendix **** 


**** 2012 and 2016 surveys on their own ***** 
eststo clear 

eststo t1: logit gwhappening resentment Democrat Republican Liberal Conservative  educ1 educ2 educ4 educ5 male age if survey==1 & white==1
eststo t2: logit gwhappening resentment Democrat Republican Liberal Conservative  educ1 educ2 educ4 educ5 male age if survey==2 &  white==1

eststo t3: logit humanactivity resentment Democrat Republican Liberal Conservative  educ1 educ2 educ4 educ5 male age if survey==1 &  white==1
eststo t4: logit humanactivity resentment Democrat Republican Liberal Conservative  educ1 educ2 educ4 educ5 male age if survey==2 & white==1


# delimit ;
esttab using a_anesbyyear.rtf, nogap se b starlevels(* .10 ** .05 *** .01) r2(%9.3f) 
	title("Belief global warming is happening / caused by humans" )
	   label nonumbers mtitles("Happening 2012" "Happening 2016" "Human caused 2012" "Human caused 2016")
	addnote("Logistic regression")
	compress replace;
 #delimit cr
 
 *** controlling for race **** 
 
 eststo clear 
 
eststo t1: logit gwhappening c.resentment##c.educlevel Democrat Republican Liberal Conservative white2  male age
eststo t2: logit humanactivity c.resentment##c.educlevel Democrat Republican Liberal Conservative white2  male age
 

# delimit ;
esttab using a_anesallraces.rtf, nogap se b starlevels(* .10 ** .05 *** .01) r2(%9.3f) 
	title("Belief global warming is happening / caused by humans" )
	   label nonumbers mtitles("Happening" "Human caused")
	addnote("Logistic regression")
	compress replace;
 #delimit cr
 
**** tables for PID figure **** 


 eststo clear 
 
	eststo pid1: logit humanactivity c.resentment##c.educlevel Democrat Republican Liberal Conservative male age income1 if white==1  & Democrat == 1
	eststo pid2: logit humanactivity c.resentment##c.educlevel  Democrat Republican Liberal Conservative male age income1 if white==1  & Republican == 1

# delimit ;
esttab using a_ANES_pid.rtf, nogap se b b(%9.4f) starlevels(* .10 ** .05 *** .01) r2(%9.3f) 
	title("Belief global warming is caused by humans" )
	  label nonumbers mtitles("Democrats" "Republicans")
	addnote("Logistic regression. Combined 2012 and 2016 data with errors clustered on survey. Includes partisan leaners")
	compress replace;
 #delimit cr
 

 
 
 ***** CCES **** 
 
 
 clear
 
use "CCES_cleaned.dta"


label var fireindex "FIRE index"

tab educlevel, sum(resent)
gen educresent=educlevel*resent
label var resent "Racial resentment"
label var educlevel "Education"
egen mean_resent = mean(resent), by(educlevel)
label variable mean_resent "Resentment by education level" 

label define educlevel 1 "HS or less" 2 "Some college" 3 "2 year degree" 4 "4 year degree" 5 "Post-grad", replace
label values educlevel educlevel

gen lowresent=.
label var lowresent "Low/high racial resentment"
replace lowresent=1 if resent<=3 & !missing(resent)
replace lowresent=0 if resent>3 & !missing(resent)

gen educlevel2 = .
replace educlevel2 = 0 if educlevel == 1
replace educlevel2 = 1 if educlevel == 4 | educlevel == 5
label var educlevel2 "Edu HS vs BA+"

egen mean_fire = mean(fire), by(educlevel)

gen educfire=educlevel*fire

gen medfire=.
label var medfire "At/below median Fire Index(2.5)"
replace medfire=1 if fire<=2.5 & !missing(fire)
replace medfire=0 if fire>2.5 & !missing(fire)
	

// Results for Table 1, part B

eststo clear 

eststo m2: logit CO2reg resentment educlevel educresent Democratic Republican Liberal Conservative Male age income1 if White==1
eststo m1: logit CO2reg resentment educlevel Democratic Republican Liberal Conservative Male age income1 if White==1
eststo m4: logit REmandate resentment educlevel educresent Democratic Republican Liberal Conservative Male age income1 if White==1
eststo m3: logit REmandate resentment educlevel Democratic Republican Liberal Conservative Male age income1 if White==1




# delimit ;
esttab using Table1CCESresults.rtf, nogap se b b(%9.4f) starlevels(* .10 ** .05 *** .01) r2(%9.3f) 
	title("Support for climate policy" )
	  label nonumbers mtitles("CO2 regulation" "CO2 regulation" "Renewable energy" "Renewable energy")
	addnote("Logistic regression. 2018 CCES data")
	compress replace;
 #delimit cr
 
 **** line graph **** 
 
 
 eststo clear 
	logit CO2reg c.resentment##c.educlevel Democrat Republican Liberal Conservative Male age income1 if White==1
	eststo edu1: margins, at(resentment=(1(.5)5) educlevel=(1))   atmeans post 
	logit CO2reg c.resentment##c.educlevel Democrat Republican Liberal Conservative Male age income1 if White==1
	eststo edu4: margins, at(resentment=(1(.5)5) educlevel=(4))  atmeans post 

	
coefplot (edu1, label (High school or less)) (edu4, label (BA degree)), ///
	ytitle ("Support for CO2 regulation" "Predicted values")   title("") legend (row(1) pos(6)) ///
	xtitle ("Racial Resentment") ///
	xlab(1 "Low" 3 "Medium" 5 "High", labsize(small)) ///
	ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%", labsize(small)) ///
	at recast(line) lwidth(*2) 
	graph save co2.gph, replace

eststo clear 
	logit RE c.resentment##c.educlevel Democrat Republican Liberal Conservative Male age income1 if White==1
	eststo edu1: margins, at(resentment=(1(.5)5) educlevel=(1))   atmeans post 
	logit RE c.resentment##c.educlevel Democrat Republican Liberal Conservative Male age income1 if White==1
	eststo edu4: margins, at(resentment=(1(.5)5) educlevel=(4))  atmeans post 
	
coefplot (edu1, label (High school or less)) (edu4, label (BA degree)), ///
	ytitle ("Support for min. renewable energy mandate" "Predicted values")   title("") legend (row(1) pos(6)) ///
	xtitle ("Racial Resentment") ///
	xlab(1 "Low" 3 "Medium" 5 "High", labsize(small)) ///
	ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%", labsize(small)) ///
	at recast(line) lwidth(*2) 
	graph save RE.gph, replace

	grc1leg co2.gph RE.gph, scheme(s1mono) row(1) graphregion(margin(none)) ysize(4) 
	graph save 2F_CCES.gph, replace
	graph export 2F_CCES.png, replace width(1800)



**** Figure 3: resentment x education **** 

eststo clear

eststo m5: logit CO2reg i.educlevel2 Democratic Republican Liberal Conservative Male age income1 if lowresent==1 & White==1
eststo m6: logit CO2reg i.educlevel2 Democratic Republican Liberal Conservative Male age income1 if lowresent==0 & White==1

eststo m7: logit REmandate i.educlevel2 Democratic Republican Liberal Conservative Male age income1 if lowresent==1 & White==1
eststo m8: logit REmandate i.educlevel2 Democratic Republican Liberal Conservative Male age income1 if lowresent==0 & White==1

	coefplot (m5, msymbol(T) label (Low racial resentment)) (m6, msymbol(D) label (High racial resentment)), bylabel(EPA regulating CO2) ///
	|| (m7) (m8), bylabel(Min renewable energy mandate) ///
	ylabel(,labsize(small)) xlabel(,labsize(small) angle(horizontal)) format(%9.2f) ///
	xline(0, lpattern(dash) lwidth(vthin)) ///
	xtitle("") /// 
	legend(rows(1)) vertical ytitle("Effect of education" "Different btw HS & BA")  ///
	title() grid(between) graphregion(margin(medlarge)) xlab(none) ///
	drop(_cons Democratic Republican Liberal Conservative Male age income1)
	
	graph save 3F_CCES.gph, replace
	graph export 3F_CCES.png, replace width(1800)

		
# delimit ;
esttab using a_cces_high_low.rtf, nogap se b b(%9.4f) starlevels(* .10 ** .05 *** .01) r2(%9.3f) 
	title("Support for climate policy" )
	  label nonumbers mtitles("CO2 regulation" "Renewable energy" )
	addnote("Logistic regression. 2018 CCES data")
	compress replace;
 #delimit cr
	 
 **** line FIRE graph **** 
 
 
 eststo clear 
	logit CO2reg c.fireindex##c.educlevel Democrat Republican Liberal Conservative Male age income1 if White==1
	eststo edu1: margins, at(fireindex=(1(.5)5) educlevel=(1))   atmeans post 
	logit CO2reg c.fireindex##c.educlevel Democrat Republican Liberal Conservative Male age income1 if White==1
	eststo edu4: margins, at(fireindex=(1(.5)5) educlevel=(4))  atmeans post 

	
coefplot (edu1, label (High school or less)) (edu4, label (BA degree)), ///
	ytitle ("Support for CO2 regulation" "Predicted values")   title("") legend (row(1) pos(6)) ///
	xtitle ("FIRE index") ///
	xlab(1 "Low" 3 "Medium" 5 "High", labsize(small)) ///
	ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%", labsize(small)) ///
	at recast(line) lwidth(*2) 
	graph save co2_fire.gph, replace

eststo clear 
	logit RE c.fireindex##c.educlevel Democrat Republican Liberal Conservative Male age income1 if White==1
	eststo edu1: margins, at(fireindex=(1(.5)5) educlevel=(1))   atmeans post 
	logit RE c.fireindex##c.educlevel Democrat Republican Liberal Conservative Male age income1 if White==1
	eststo edu4: margins, at(fireindex=(1(.5)5) educlevel=(4))  atmeans post 
	
coefplot (edu1, label (High school or less)) (edu4, label (BA degree)), ///
	ytitle ("Support for min. renewable energy mandate" "Predicted values")   title("") legend (row(1) pos(6)) ///
	xtitle ("FIRE index") ///
	xlab(1 "Low" 3 "Medium" 5 "High", labsize(small)) ///
	ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%", labsize(small)) ///
	at recast(line) lwidth(*2) 
	graph save RE_fire.gph, replace 
	
	
	grc1leg co2_fire.gph RE_fire.gph, row(1) graphregion(margin(none)) ysize(4) 
	graph save 5F_CCES_FIRE.gph, replace
	graph export 5F_CCES_FIRE.png, replace width(1800)

	******** CCES appendix ******** 
	
	
	eststo clear 

	eststo m5: logit CO2reg  i.educlevel Democratic Republican Liberal Conservative  Male age if lowresent==1 & White==1
	eststo m6: logit CO2reg  i.educlevel Democratic Republican Liberal Conservative  Male age if lowresent==0 & White==1
	eststo m7: logit REmandate  i.educlevel Democratic Republican Liberal Conservative  Male age if lowresent==1 & White==1
	eststo m8: logit REmandate  i.educlevel Democratic Republican Liberal Conservative  Male age if lowresent==0 & White==1

	coefplot (m5, msymbol(D) label (Low racial resentment)) (m6, msymbol(T) label (High racial resentment)), bylabel (EPA regulating CO2) ///
	|| (m7) (m8), bylabel (Minimum renewable mandate) ///
	ylabel(,labsize(small)) xlabel(,labsize(small) angle(horizontal)) format(%9.2f) ///
	xline(0, lpattern(dash) lcolor(gray) lwidth(vthin)) ///
	legend(off) scheme(s1mono) ///
	title() grid(between) graphregion(margin(medlarge)) ///
	drop(_cons Democratic Republican Liberal Conservative Male age income1)
	
	graph save a_cces_eduxfire.gph, replace
	graph export a_cces_eduxfire.png, replace width(1800)
	
**** appendix of models by partisanship  **** 
	
	
 eststo clear 
	logit CO2reg c.resentment##c.educlevel   Male age income1 if White==1 & Democrat == 1
	eststo edu1: margins, at(resentment=(1(.5)5) educlevel=(1))   atmeans post 
	logit CO2reg c.resentment##c.educlevel   Male age income1 if White==1 & Democrat == 1
	eststo edu2: margins, at(resentment=(1(.5)5) educlevel=(4))  atmeans post 
	logit CO2reg c.resentment##c.educlevel    Male age income1 if White==1 & Republican == 1
	eststo edu3: margins, at(resentment=(1(.5)5) educlevel=(1))   atmeans post 
	logit CO2reg c.resentment##c.educlevel    Male age income1 if White==1 & Republican == 1
	eststo edu4: margins, at(resentment=(1(.5)5) educlevel=(4))  atmeans post 


	
coefplot (edu1, label (High school or less)) (edu2, label (BA degree)), ///
	ytitle ("Support for CO2 regulation")   title("Democrats") legend (row(1) pos(6)) ///
	xtitle ("Racial Resentment") ///
	xlab(1 "Low" 3 "Medium" 5 "High", labsize(small)) ///
	ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%", labsize(small)) ///
	at recast(line) lwidth(*2) ciopts(recast(rline) lpattern(dash)) 
	graph save co2_dem, replace
	
	
	
coefplot (edu3, label (High school or less)) (edu4, label (BA degree)), ///
	ytitle ("Support for CO2 regulation")   title("Republicans") legend (row(1) pos(6)) ///
	xtitle ("Racial Resentment") ///
	xlab(1 "Low" 3 "Medium" 5 "High", labsize(small)) ///
	ylab(0 "0%" .25 "25%" .5 "50%" .75 "75%" 1 "100%", labsize(small)) ///
	at recast(line) lwidth(*2) ciopts(recast(rline) lpattern(dash)) 
	graph save co2_rep, replace

graph combine co2_dem.gph co2_rep.gph, common row(1) graphregion(margin(none)) ysize(4) 
graph save a_cces_pid.gph, replace
graph export a_cces_pid.png, replace width(1800)


 eststo clear 
	eststo pid1: logit CO2reg c.resentment##c.educlevel   Male age income1 if White==1 & Democrat == 1
	eststo pid2: logit CO2reg c.resentment##c.educlevel    Male age income1 if White==1 & Republican == 1
	eststo pid3: logit REmandate c.resentment##c.educlevel   Male age income1 if White==1 & Democrat == 1
	eststo pid4: logit REmandate c.resentment##c.educlevel    Male age income1 if White==1 & Republican == 1

	

# delimit ;
esttab using a_cces_pid.rtf, nogap se b b(%9.4f) starlevels(* .10 ** .05 *** .01) r2(%9.3f) 
	title("Support for climate policy" )
	  label nonumbers mtitles("CO2 regulation - Dems" "CO2 regulation - Reps" "Renewable energy - Dems" "Renewable energy - Reps")
	addnote("Logistic regression. 2018 CCES data")
	compress replace;
 #delimit cr
 

